//结束页
import {Sprite} from "../base/Sprite.js";
import {DataStore} from "../base/DataStore.js";
const screenWidth    = window.innerWidth
const screenHeight   = window.innerHeight
const rpx=DataStore.getRpx()
export class Gameover extends Sprite {
    constructor() {
        const image = Sprite.getImage('endbg');
        super(image,
            0, 0,
            image.width, image.height,
            0, 0,
            DataStore.getInstance().canvas.width, DataStore.getInstance().canvas.height);
    }
    drawEndTit(){
        const image = Sprite.getImage('gameover');
        super.draw(image,
            0, 0,
            image.width, image.height,
            (screenWidth-image.width/2*rpx)/2,350*rpx,
            image.width/2*rpx, image.height/2*rpx);
        
    }
    checkIsFingerOnAir(obj) {//判断是否在按键上

        const deviation = 30
        const a= !!(   x >= this.birdsX - deviation
            && y >= this.birdsY - deviation
            && x <= this.birdsX + this.width + deviation
            && y <= this.birdsY + this.height + deviation  )

             if(a){
                this.hasChoosen=true
             }else{
                 this.selectBottom=false
             }
             
    }

    initbottomEvent(){
        DataStore.getInstance().canvas.addEventListener('touchend', ((e) => {
            e.preventDefault()
            let x = e.changedTouches[0].clientX
            let y = e.changedTouches[0].clientY
            
            this.checkIsFingerOnAir({'x':x,'y':y})
          }))
    }

    drawEndHand(){
        const image = Sprite.getImage('hand');
        super.draw(image,
            0, 0,
            image.width, image.height,
            (screenWidth-image.width/2*rpx)/2,370*rpx,
            image.width/2*rpx, image.height/2*rpx);
        
    }
}